<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: cross_sell_groups.php 35 2013-09-21 11:55:05Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 35 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:55:05 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');

switch ($_GET['action']) {
	case 'insert':
	case 'save':
		$cross_sell_id = $_GET['oID'];

		$languages = get_languages();
		for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			$cross_sell_name_array = $_POST['cross_sell_group_name'];
			$language_id = $languages[$i]['id'];

			$sql_data_array = array('groupname' => $cross_sell_name_array[$language_id]);

			if ($_GET['action'] == 'insert') {
				if (!not_null($cross_sell_id)) {
					$next_id = $db->db_query("SELECT
													MAX(products_xsell_grp_name_id) AS products_xsell_grp_name_id
												FROM
													".TABLE_PRODUCTS_XSELL_GROUPS);
					$cross_sell_id = $next_id->fields['products_xsell_grp_name_id'] + 1;
				}

				$insert_sql_data = array('products_xsell_grp_name_id' => $cross_sell_id,
										'language_id' => $language_id);
				$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
				$db->db_perform(TABLE_PRODUCTS_XSELL_GROUPS, $sql_data_array);

			} elseif ($_GET['action'] == 'save')
				$db->db_perform(TABLE_PRODUCTS_XSELL_GROUPS, $sql_data_array, 'update', "products_xsell_grp_name_id = ".$db->db_prepare($cross_sell_id)." and language_id = '".$language_id."'");
		}

		redirect(href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$cross_sell_id));
		break;

	case 'deleteconfirm':
		$oID =$_GET['oID'];

		$db->db_query("DELETE FROM
							".TABLE_PRODUCTS_XSELL_GROUPS."
						WHERE
							products_xsell_grp_name_id = ".$db->db_prepare($oID));

		redirect(href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page']));
		break;

	case 'delete':
		$oID = $_GET['oID'];

		$status = $db->db_query("SELECT
									COUNT(*) AS count
								FROM
									".TABLE_PRODUCTS_XSELL."
								WHERE
									products_xsell_grp_name_id = ".$db->db_prepare($oID));

		$remove_status = true;
		if ($status < 1) {
			$remove_status = false;
			$message_stack->add(ERROR_STATUS_USED_IN_CROSS_SELLS, 'error');
		}
		break;
}
require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellpadding="0" cellspacing="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
			<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
    	</table>
	</td>
    <td class="boxCenter" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td>
			<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
 		 		<tr>
		    		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
		  		</tr>
			</table>
		</td>
      </tr>
      <tr>
        <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_XSELL_GROUP_NAME; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
				<?php
				  $sql = "SELECT 
				  				products_xsell_grp_name_id, 
				  				groupname 
				  			FROM 
				  				".TABLE_PRODUCTS_XSELL_GROUPS." 
				  			WHERE 
				  				language_id = '".$_SESSION['languages_id']."' 
				  			ORDER BY 
				  				products_xsell_grp_name_id";
				  
				  $query = page_break_create($_POST['per_site'], $_GET['page'], $sql, 'price_change.php');
				  
				  $cross_sell = $query['query'];
				  $rows=1;
				  while (!$cross_sell->EOF) {
				    if (((!$_GET['oID']) || ($_GET['oID'] == $cross_sell->fields['products_xsell_grp_name_id'])) && (!$oInfo) && (substr($_GET['action'], 0, 3) != 'new')) {
				      $oInfo = new objectInfo($cross_sell->fields);
				    }
					if ($rows % 2 == 0)
						$f = 'dataTableRow';
					else
						$f = '';
				    if ( (is_object($oInfo)) && ($cross_sell->fields['products_xsell_grp_name_id'] == $oInfo->products_xsell_grp_name_id) ) {
				      echo '<tr class="dataTableRowSelected" onmouseover="this.style.cursor=\'pointer\'" onclick="document.location.href=\''.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$oInfo->products_xsell_grp_name_id.'&action=edit').'\'">'."\n";
				    } else {
				      echo '<tr class="'. $f.'" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'pointer\'" onmouseout="this.className=\''. $f.'\'" onclick="document.location.href=\''.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$cross_sell->fields['products_xsell_grp_name_id']).'\'">'."\n";
				    }


				      echo '  <td class="dataTableContent">'.$cross_sell->fields['groupname'].'</td>'."\n";

				?>
				                <td class="dataTableContent" align="right"><?php if ( (is_object($oInfo)) && ($cross_sell->fields['products_xsell_grp_name_id'] == $oInfo->products_xsell_grp_name_id) ) { echo image(DIR_WS_IMAGES.'icon_arrow_right.gif', ''); } else { echo '<a href="'.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$cross_sell->fields['products_xsell_grp_name_id']).'">'.image(DIR_WS_IMAGES.'icon_info.gif', IMAGE_ICON_INFO).'</a>'; } ?>&nbsp;</td>
				<?php
					echo '</tr>';
				  	$rows++;
				  	$cross_sell->MoveNext();
				}
				?>
              <tr>
                <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                 <tr class="page_break">
					<td class="smallText" valign="top" width="33.3%"><?php echo 'Angezeigt werden '.$query['from'].' bis '.$query['to'].' (von insgesamt '.$query['total'].' Artikeln)'; ?></td>
					<td class="smallText" align="center" width="33.3%"></td>
					<td class="smallText" align="right" width="33.3%">
						Gruppen pro Seite: <?php echo $query['page_break']->perSiteDropdown($_GET['page']); ?>
					</td>
				</tr>
				<tr><td align="center" colspan="3"><?php echo '<br />'.$query['links']; ?></td></tr>
					<?php
					  if (substr($_GET['action'], 0, 3) != 'new') {
					?>
                  <tr>
                    <td colspan="3" align="right"><?php echo '<a class="button" onclick="this.blur();" href="'.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&action=new').'">'.BUTTON_INSERT.'</a>'; ?></td>
                  </tr>
					<?php
					  }
					?>
                </table></td>
              </tr>
            </table></td>
			<?php
			  $heading = array();
			  $contents = array();
			  switch ($_GET['action']) {
			    case 'new':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_NEW_XSELL_GROUP.'</b>');

			      $contents = array('form' => draw_form('status', FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&action=insert'));
			      $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);

			      $cross_sell_inputs_string = '';
			      $languages = get_languages();
			      for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			        $cross_sell_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('cross_sell_group_name['.$languages[$i]['id'].']');
			      }

			      $contents[] = array('text' => '<br />'.TEXT_INFO_XSELL_GROUP_NAME.$cross_sell_inputs_string);
			      $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'.BUTTON_INSERT.'</button> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page']).'">'.BUTTON_CANCEL.'</a>');
			      break;

			    case 'edit':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_EDIT_XSELL_GROUP.'</b>');

			      $contents = array('form' => draw_form('status', FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$oInfo->products_xsell_grp_name_id .'&action=save'));
			      $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);

			      $cross_sell_inputs_string = '';
			      $languages = get_languages();
			      for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			        $cross_sell_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('cross_sell_group_name['.$languages[$i]['id'].']', get_cross_sell_name($oInfo->products_xsell_grp_name_id, $languages[$i]['id']));
			      }

			      $contents[] = array('text' => '<br />'.TEXT_INFO_XSELL_GROUP_NAME.$cross_sell_inputs_string);
			      $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'.BUTTON_UPDATE.'</button> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$oInfo->products_xsell_grp_name_id).'">'.BUTTON_CANCEL.'</a>');
			      break;

			    case 'delete':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_DELETE_XSELL_GROUP.'</b>');

			      $contents = array('form' => draw_form('status', FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$oInfo->products_xsell_grp_name_id .'&action=deleteconfirm'));
			      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
			      $contents[] = array('text' => '<br /><b>'.$oInfo->orders_status_name.'</b>');
			      if ($remove_status) $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'.BUTTON_DELETE.'</button> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$oInfo->products_xsell_grp_name_id).'">'.BUTTON_CANCEL.'</a>');
			      break;

			    default:
			      if (is_object($oInfo)) {
			        $heading[] = array('text' => '<b>'.$oInfo->orders_status_name.'</b>');

			        $contents[] = array('align' => 'center', 'text' => '<a class="button" onclick="this.blur();" href="'.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$oInfo->products_xsell_grp_name_id.'&action=edit').'">'.BUTTON_EDIT.'</a> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_XSELL_GROUPS, 'page='.$_GET['page'].'&oID='.$oInfo->products_xsell_grp_name_id.'&action=delete').'">'.BUTTON_DELETE.'</a>');

			        $cross_sell_inputs_string = '';
			        $languages = get_languages();
			        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			          $cross_sell_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.get_cross_sell_name($oInfo->products_xsell_grp_name_id, $languages[$i]['id']);
			        }

			        $contents[] = array('text' => $cross_sell_inputs_string);
			      }
			      break;
			  }

			if ( (not_null($heading)) && (not_null($contents)) ) {
				echo '<td width="25%" class="border" valign="top">'."\n";
				$box = new box();
				echo $box->infoBox($heading, $contents);
				echo '</td>'."\n";
			}
			?>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>